﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BooksManagermentSystem
{
    public partial class AddAdmin_form : Form
    {
        public AddAdmin_form()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            string account = textBox2.Text;
            if(DBhelper.checkAdmin(account))
            {
                MessageBox.Show("此管理员已存在");
                return;
            }

            DialogResult rd = MessageBox.Show($"姓名：【{name}】\r\n用户名：【{account}】\r\n确定要注册吗？", "提示", MessageBoxButtons.YesNo);
            if (rd == DialogResult.Yes)
            {
                string sql = $"insert into AdminInfo values('{account}','123456','{name}')";
                if(DBhelper.NonQuery(sql))
                {
                    MessageBox.Show("注册成功！");
                }
                else
                {
                    MessageBox.Show("注册失败！");
                }
            }
            textBox2.Focus();
        }
    }
}
